<?php
if(!defined('INCLUDE')) exit();

// Require needed files
require_once CORE_DIRECTORY.OS_PATH_SEPARATOR.'baseMetadata.php';
require_once CORE_DIRECTORY.OS_PATH_SEPARATOR.'file.php';

$pluginList = array();
// Function which load needed file to allow plugin instanciation
// Populate the $pluginList array
function loadPlugin_metadata($e)
{
	global $pluginList;
	if(is_dir($e) && file_exists($e.OS_PATH_SEPARATOR.'index.php'))
	{
		debug($e.OS_PATH_SEPARATOR.'index.php', 'File "%v" loaded', JGLIB_DEBUG_INFO);
		include_once $e.OS_PATH_SEPARATOR.'index.php';
		$pluginList[] = 'metadataPlugins_'.$pluginName;
	}
}

// Scan plugin directory and load them
$scan = new Scandirr(METADATA_PLUGINS_DIRECTORY, 'loadPlugin_metadata', 1);

if(empty($pluginList))
{
	throw new Exception('No metadataPlugins found');
}

// For each file which are handled (from upload plugin)
if(isForeachable($files)) foreach($files as $file)
{
	// For each plugin
	foreach($pluginList as $plugin)
	{
		$p = new $plugin($file);
		// Is this plugin can handled this file ?
		if(!in_array($plugin, $upload->unactivateMetadataPlugins()) &&
			(
				$p->getExtensionHandle() === true
				|| in_array($file->getExtension(), $p->getExtensionHandle()) 
				|| in_array($file->getMimeType(),  $p->getMimeHandle())
			)
		)
		{
			// Processing
			debug($p->saveMeta(),'Plugin "'.$p->getPluginName().'" lauched for file "'.$file.'", Result', JGLIB_DEBUG_PER1);
		}
	}
}
